package cc.sunni.rabbitmqdelayedmessagedemo.component;

import cc.sunni.rabbitmqdelayedmessagedemo.config.DelayedMessageConfig;
import cc.sunni.rabbitmqdelayedmessagedemo.entity.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@RabbitListener(queues = DelayedMessageConfig.QUEUE_NAME)
public class DelayedMessageReceiver {
    public static final Logger log = LoggerFactory.getLogger(DelayedMessageReceiver.class);

    @RabbitHandler
    public void process(String msg) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("接收时间:" + sdf.format(new Date()));
        log.info("消息内容:" + msg);
        // 业务处理xxx
    }

    @RabbitHandler
    public void process(Order order) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("接收时间:" + sdf.format(new Date()));
        log.info("消息内容:" + order);
        // 业务处理xxx
    }
}